/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pds_facebook.Adapter;

import com.restfb.Connection;
import com.restfb.DefaultFacebookClient;
import com.restfb.FacebookClient;
import com.restfb.types.Post;
import com.restfb.types.User;

/**
 *
 * @author Joao
 *
 * Essa classe retorna um novo objeto amigo, utilizando as caracteristicas de um
 * facebook friend
 */
public class FriendAdapter {

    String token;
    String userid;

    public FriendAdapter(String token, String userid) {
        this.token = token;
        this.userid = userid;
    }

    public static MyFriend getFriend(String token, String userid) {
        FacebookClient facebookClient = new DefaultFacebookClient(token);
        User user = facebookClient.fetchObject(userid, User.class);
        Connection<Post> feed = facebookClient.fetchConnection(userid + "/feed", Post.class);
        
        String f = "";
        if(!feed.getData().isEmpty())
            f = String.valueOf(feed.getData().get(0).getPlace());

        MyFriend returnable = new MyFriend(user.getName(), user.getBirthday(), user.getGender(), user.getRelationshipStatus(), f);

        return returnable;
    }
}
